GdkEvent *event,
gpointer data )
{
- /* If you return FALSE in the "delete_event" signal handler,
+ /* If you return FALSE in the "delete-event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
* This is useful for popping up 'are you sure you want to quit?'
g_print ("delete event occurred\n");
/* Change TRUE to FALSE and the main window will be destroyed with
- * a "delete_event". */
+ * a "delete-event". */
return TRUE;
}
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- /* When the window is given the "delete_event" signal (this is given
+ /* When the window is given the "delete-event" signal (this is given
* by the window manager, usually by the "close" option, or on the
* titlebar), we ask it to call the delete_event () function
* as defined above. The data passed to the callback
* function is NULL and is ignored in the callback function. */
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
/* Here we connect the "destroy" event to a signal handler.
* This event occurs when we call gtk_widget_destroy() on the window,
- * or if we return FALSE in the "delete_event" callback. */
- g_signal_connect (G_OBJECT (window), "destroy",
+ * or if we return FALSE in the "delete-event" callback. */
+ g_signal_connect (window, "destroy",
G_CALLBACK (destroy), NULL);
/* Sets the border width of the window. */
}
</programlisting>
-<para>The next callback is a bit special. The "delete_event" occurs when the
+<para>The next callback is a bit special. The "delete-event" occurs when the
window manager sends this event to the application. We have a choice
here as to what to do about these events. We can ignore them, make
some sort of response, or simply quit the application.</para>
in the window widget as the object to destroy. The second is emitted
when, in the "delete_event" handler, we return FALSE.
-The <literal>G_OBJECT</literal> and <literal>G_CALLBACK</literal> are macros
-that perform type casting and checking for us, as well as aid the readability of
+The <literal>G_CALLBACK</literal> is a macro
+that performs type casting and checking for us, as well as aid the readability of
the code.</para>
<programlisting role="C">
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (destroy), NULL);
</programlisting>
callback function, which simply exits GTK.</para>
<para>Another course of events is to use the window manager to kill the
-window, which will cause the "delete_event" to be emitted. This will
-call our "delete_event" handler. If we return TRUE here, the window
+window, which will cause the "delete-event" to be emitted. This will
+call our "delete-event" handler. If we return TRUE here, the window
will be left as is and nothing will happen. Returning FALSE will cause
GTK to emit the "destroy" signal which of course calls the "destroy"
callback, exiting GTK.</para>
/* Here we just set a handler for delete_event that immediately
* exits GTK. */
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
/* Sets the border width of the window. */
/* You should always remember to connect the delete_event signal
* to the main window. This is very important for proper intuitive
* behavior */
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Set a handler for delete_event that immediately
* exits GTK. */
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete_event), NULL);
/* Sets the border width of the window. */
/* Create "Quit" button */
button = gtk_button_new_with_label ("Quit");
- /* When the button is clicked, we call the "delete_event" function
+ /* When the button is clicked, we call the "delete-event" function
* and the program exits */
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (delete_event), NULL);
gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!");
/* It's a good idea to do this for all windows. */
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
/* Sets the border width of the window. */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (close_application),
NULL);
/* Standard window-creating stuff */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
gtk_window_set_title (GTK_WINDOW (window), "range controls");
</programlisting>
<para>You will notice that the program does not call g_signal_connect()
-for the "delete_event", but only for the "destroy" signal. This will
+for the "delete-event", but only for the "destroy" signal. This will
still perform the desired function, because an unhandled
-"delete_event" will result in a "destroy" signal being given to the
+"delete-event" will result in a "destroy" signal being given to the
window.</para>
</sect1>
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
gtk_window_set_title (GTK_WINDOW (window), "Arrow Buttons");
/* It's a good idea to do this for all windows. */
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
/* Sets the border width of the window. */
pdata->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (pdata->window), TRUE);
- g_signal_connect (G_OBJECT (pdata->window), "destroy",
+ g_signal_connect (pdata->window, "destroy",
G_CALLBACK (destroy_progress),
(gpointer) pdata);
gtk_window_set_title (GTK_WINDOW (pdata->window), "GtkProgressBar");
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (close_application), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
gtk_window_set_title (GTK_WINDOW (window), "GTK Statusbar Example");
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (exit), NULL);
vbox = gtk_vbox_new (FALSE, 1);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
gtk_window_set_title (GTK_WINDOW (window), "GTK Entry");
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
- g_signal_connect_swapped (G_OBJECT (window), "delete_event",
+ g_signal_connect_swapped (window, "delete-event",
G_CALLBACK (gtk_widget_destroy),
G_OBJECT (window));
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "destroy",
+ g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
/* Attach to the "delete" and "destroy" events so we can exit */
- g_signal_connect (GTK_OBJECT (window), "delete_event",
- GTK_SIGNAL_FUNC (destroy_window), (gpointer) window);
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (destroy_window), (gpointer) window);
/* Create drawingarea, set size and catch button events */
GTK_WINDOW (dialog)->allow_shrink = TRUE;
/* typically we quit if someone tries to close us */
- g_signal_connect (G_OBJECT (dialog), "delete_event",
+ g_signal_connect (dialog, "delete-event",
G_CALLBACK (delete_event), NULL);
/* we need to realize the window because we use pixmaps for
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (delete), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
gtk_window_set_title (GTK_WINDOW (window), "GTK Menu Test");
- g_signal_connect (G_OBJECT (window), "delete_event",
+ g_signal_connect (window, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
/* Init the menu-widget, and remember -- never